package edu.pku.sei.transformation.tgg.action;

import java.util.List;

import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.TreeViewer;

import edu.pku.sei.modeler.actions.registry.EditorActionGroup;
import edu.pku.sei.modeler.actions.registry.IActionProvider;
import edu.pku.sei.modeler.actions.registry.TreeViewActionGroup;
import edu.pku.sei.modeler.model.structure.MetaDiagram;
import edu.pku.sei.transformation.editor.internal.TransformationEditorProject;
import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.model.Transformation;

public class TGGActionProvider implements IActionProvider {

	@Override
	public String getProjectNature() {
		return TransformationEditorProject.PROJECT_NATURE;
	}

	@Override
	public Action getTreeViewerDoubleClickAction(Object selectElement) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public TreeViewActionGroup getTreeViewerMenuActionGroup(TreeViewer tv) {
		return new TGGTreeViewActionGroup(tv);
	}

	@Override
	public EditorActionGroup getEditorActionGroup(EditPartViewer viewer,
			ActionRegistry defaultActions, MetaDiagram diagram) {
		// TODO Auto-generated method stub
		return null;
	}
	private class TGGTreeViewActionGroup extends TreeViewActionGroup {

		public TGGTreeViewActionGroup(TreeViewer tv) {
			super(tv);
		}

		@Override
		public void fillContextMenu(IMenuManager menu) {
			List selectedElement = super.getSelection();
			if (selectedElement.size() < 1)
				return;
			Object treeObj = selectedElement.get(0);
				
			if (treeObj instanceof AtomicTransformation) {
				GenTGGAction genQVT = new GenTGGAction((AtomicTransformation) treeObj);
				menu.add(genQVT);	
			} 

		}

	}

}
